package com.woniu.finance.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.finance.entity.RoleMenu;
import com.woniu.finance.entity.RolePermission;
import com.woniu.finance.mapper.RolePermissionMapper;
import com.woniu.finance.service.IRolePermissionService;
import com.woniu.util.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色权限表 服务实现类
 * </p>
 *
 * @author o
 * @since 2023-04-25
 */
@Service
public class RolePermissionServiceImpl implements IRolePermissionService {

    @Autowired(required = false)
    private RolePermissionMapper rolePermissionMapper;

    @Override
    public HttpResult<?> saveRolePermission(RolePermission rolePermission) {
        try {
            rolePermissionMapper.insert(rolePermission);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> removeRolePermission(Integer id) {
        try {
            rolePermissionMapper.deleteById(id);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> modifyRolePermission(RolePermission rolePermission) {
        try {
            rolePermissionMapper.updateById(rolePermission);
            return new HttpResult<>().ok();
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> findAllRolePermission() {
        try {
            List<RolePermission> rolePermission = rolePermissionMapper.selectList(null);
            return new HttpResult<>().ok(rolePermission);
        }catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> findAllRolePermissionById(Integer id) {
        try {
            RolePermission rolePermission = rolePermissionMapper.selectById(id);
            return new HttpResult<>().ok(rolePermission);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }
}
